<?php
/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Education
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
class Education_Widget_ProfileEducationsController extends Engine_Content_Widget_Abstract
{
  protected $_childCount;
  
  public function indexAction()
  {
    // Don't render this if not authorized
    $viewer = Engine_Api::_()->user()->getViewer();
    if( !Engine_Api::_()->core()->hasSubject() ) {
      return $this->setNoRender();
    }

    // Get subject and check auth
    $subject = Engine_Api::_()->core()->getSubject();
    if( !$subject->authorization()->isAllowed($viewer, 'view') ) {
      return $this->setNoRender();
    }   

    if( !($subject instanceof User_Model_User) ) {
      return $this->setNoRender();
    }    
    
    

    $values = array(
      'limit' => $this->_getParam('max', 5),
      'order' => $this->_getParam('order', 'year'),
      'user' => $subject,
    );
    
    
    $this->view->paginator = $paginator = Engine_Api::_()->education()->getEducationsPaginator($values);

    // Do not render if nothing to show
    if( $paginator->getTotalItemCount() <= 0 ) {
      return $this->setNoRender();
    }

    $this->view->showphoto = $this->_getParam('showphoto', 1);
    $this->view->showdetails = $this->_getParam('showdetails', 1); 
    
    $this->view->showmeta = $this->_getParam('showmeta', 1); 
    $this->view->showdescription = $this->_getParam('showdescription', 0); 
    
    
    // Add count to title if configured
    $this->_childCount = $paginator->getTotalItemCount();

  }

  public function getChildCount()
  {
    return $this->_childCount;
  }
}